package org.maxgroundstation.groundstation.view;

import java.awt.Graphics;

import javax.swing.JPanel;
import javax.swing.OverlayLayout;

import org.maxgroundstation.groundstation.GroundStation;
import org.maxgroundstation.groundstation.view.overlay.CameraOverlayComponent;

/**
 * A panel for viewing camera video.
 * @author Scott Davis
 * 
 * Copyright (C) 2010  Scott Davis
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
@SuppressWarnings("serial")
public class CameraPanel extends JPanel {
    
    // Data members.
    private long lastPaint;
    
    /**
     * Constructor
     * @param gs the ground station.
     */
    public CameraPanel(GroundStation gs) {
        super();
        
        lastPaint = 0L;
        
        // Set overlay layout.
        setLayout(new OverlayLayout(this));
        
        // Create new video display.
        VideoDisplay videoDisplay = new VideoDisplay(gs, this);
        
        // Create new camera overlay.
        CameraOverlayComponent cameraOverlay = new CameraOverlayComponent(gs, this);
        
        // Add components in top-down display order.
        add(cameraOverlay);
        add(videoDisplay);
    }
    
    /**
     * Gets the last time the panel was painted.
     * @return milliseconds time.
     */
    public long getLastTimePainted() {
        return lastPaint;
    }
    
    @Override
    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        
        // Record last time painted.
        lastPaint = System.currentTimeMillis();
    }
}